
import { Button, Space, Tag } from 'antd';
import request from 'umi-request';

import { ProList } from '@ant-design/pro-components';
import http from '@/api';
import {getProductList} from '@/api/modules/product';

type ProductItem = {
  url: string;
  id: number;
  number: number;
  introduction: string;
  labels: {
	name: string;
	color: string;
  }[];
  state: string;
  comments: number;
  created_at: string;
  updated_at: string;
  closed_at?: string;
  product: string
};

export default () => (
  <ProList<ProductItem>
	toolBarRender={() => {
	  return [
		<Button key="3" type="primary">
		  新建
		</Button>,
	  ];
	}}
	search={{
	  filterType: 'light',
	}}
	rowKey="name"
	headerTitle="项目集列表"
	request={async (params = {} as Record<string, any>) =>
	  request<{
		data: ProductItem[];
	  }>(getProductList, {
		params,
	  })
	}
	pagination={{
	  pageSize: 9,
	}}
	showActions="hover"
	metas={{
	  title: {
		dataIndex: 'product',
		title: '用户',
	  },
	  avatar: {
		dataIndex: 'avatar',
		search: false,
	  },
	  description: {
		dataIndex: 'introduction',
		search: false,
	  },
	  subTitle: {
		dataIndex: 'labels',
		render: (_, row) => {
		  return (
			<Space size={0}>
			  {row.labels?.map((label: { name: string }) => (
				<Tag color="blue" key={label.name}>
				  {label.name}
				</Tag>
			  ))}
			</Space>
		  );
		},
		search: false,
	  },
	  actions: {
		render: (text, row) => [
		  <a
			href={row.url}
			target="_blank"
			rel="noopener noreferrer"
			key="link"
		  >
			编辑
		  </a>,
		  <a
			href={row.url}
			target="_blank"
			rel="noopener noreferrer"
			key="warning"
		  >
			查看
		  </a>,
		  <a
			href={row.url}
			target="_blank"
			rel="noopener noreferrer"
			key="view"
		  >
			删除
		  </a>,
		],
		search: false,
	  },
	  status: {
		// 自己扩展的字段，主要用于筛选，不在列表中显示
		title: '状态',
		valueType: 'select',
		valueEnum: {
		  all: { text: '全部', status: 'Default' },
		  open: {
			text: '未开始',
			status: 'Error',
		  },
		  closed: {
			text: '进行中',
			status: 'Success',
		  },
		  processing: {
			text: '已完成',
			status: 'Processing',
		  },
		},
	  },
	}}
  />
);
